import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { OrderSettlementBo } from '@/api/business/order/types'
import { ComponentInternalInstance } from 'vue'

export enum Api {
  list = '/order/list',
  detail = '/order/detail',
  stopCharge = 'order/stopCharge',
  settle = 'order/settle',
  resettle = 'order/resettle',
  batchSettle = 'order/batchSettle',
  debit = 'order/debit',
  deal = 'order/deal',
  notify = 'order/notify',
  export = 'order/export',
}

// 获取设备详情
export const stopCharge = (data: string) => {
  return request({
    url: Api.stopCharge,
    method: 'post',
    data,
  })
}

// 获取列表
export const getOrderList = (data): AxiosPromise<any> => {
  return request({
    url: Api.list,
    method: 'post',
    data,
  })
}

// 获取设备详情
export const orderDetail = (data: any) => {
  return request({
    url: Api.detail,
    method: 'post',
    data,
  })
}

// 结算
export const orderSettle = (data: OrderSettlementBo) => {
  return request({
    url: Api.settle,
    method: 'post',
    data,
  })
}

// 重新结算
export const orderResettle = (data: OrderSettlementBo) => {
  return request({
    url: Api.resettle,
    method: 'post',
    data,
  })
}

// 批量结算
export const orderBatchSettle = (data: (string | number)[]) => {
  return request({
    url: Api.batchSettle,
    method: 'post',
    data,
  })
}

// 扣款
export const orderDebit = (data: OrderSettlementBo) => {
  return request({
    url: Api.debit,
    method: 'post',
    data,
  })
}

// 分成
export const orderDeal = (data: any) => {
  return request({
    url: Api.deal,
    method: 'post',
    data,
  })
}

// 通知
export const orderNotify = (data: any) => {
  return request({
    url: Api.notify,
    method: 'post',
    data,
  })
}

// 导出
export const orderExport = (data: any) => {
  const { proxy } = getCurrentInstance() as ComponentInternalInstance
  proxy?.download(Api.export, data, `order_${new Date().getTime()}.xlsx`)
  return request({
    url: Api.export,
    method: 'post',
    data,
  })
}
